package com.boang.set;

import java.util.Comparator;
import java.util.TreeSet;

/*
    @author:sa
    @date:2024/11/29 13:35
*/
public class TreeSetDemo {
    public static void main(String[] args) {
//        m1();
//        m2();
        TreeSet<Programmer> set = new TreeSet<>(new Comparator<Programmer>() {
            @Override
            public int compare(Programmer o1, Programmer o2) {
                return o1.name.compareTo(o2.name);
            }
        });
        set.add(new Programmer("张三",20));
        set.add(new Programmer("李四",30));
        set.add(new Programmer("李四", 30));
        System.out.println(set);
    }

    private static void m2() {
        TreeSet<String> set = new TreeSet<>();
        set.add("张三");
        set.add("李四");
        set.add("李四");
        System.out.println(set);
    }

    private static void m1() {
        TreeSet<Student> set = new TreeSet<>();
        set.add(new Student("张三",20));
        set.add(new Student("李四",30));
        set.add(new Student("李四", 30));
        System.out.println(set);
    }
}